﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WFNetLib;
using WFOffice2007;


namespace CMOSTestLib
{
    public class TestReport
    {
        public static void MakeReport(string filename)
        {
            WordReport report = new WordReport();
            double d;
            report.CreateNewDocument(System.Windows.Forms.Application.StartupPath + "\\测试报告模板.dot");
            report.InsertValue("报告生成时间", DateTime.Now.ToString("yyyy.MM.dd   HH:mm"));
            report.InsertValue("芯片编号", SystemParam.DeviceID);
            report.InsertValue("环境温度", SystemParam.Temperature.ToString("F1"));
            report.InsertValue("环境光强", SystemParam.lx.ToString("F1"));
            report.InsertValue("饱和输出", Calc1.miu_y[Calc1.SaturatedIndex].ToString("F6"));
            report.InsertValue("系统增益", Calc1.OverAllGain_K.ToString("F6"));
            d = (Calc1.AverageDarkSignal_k * 1000) / Calc1.OverAllGain_K;
            report.InsertValue("平均暗电流", d.ToString("F6"));
            report.InsertValue("动态范围", Calc1.DR.ToString("F6"));
            report.InsertValue("DSUN", Calc2.DSNU1288.ToString("F6"));
            report.InsertValue("PRUN", Calc2.PRNU1288.ToString("F6"));
            report.InsertPicture("光电响应曲线", SystemParam.TempPicPath + "1.JPG", 300, 122);
            report.InsertPicture("平均暗信号", SystemParam.TempPicPath + "2.jpg", 300, 122);
            report.InsertPicture("暗信号均方差", SystemParam.TempPicPath + "3.jpg", 300, 122);
            report.InsertPicture("信噪比", SystemParam.TempPicPath + "4.jpg", 300, 122);


            report.InsertValue("亮点个数", Calc2.LightPoints.Count.ToString());
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < Calc2.LightPoints.Count; i++)
            {
                sb.Append(String.Format("[{0,4},{1,4}]", (Calc2.LightPoints[i].n + 1).ToString(), (Calc2.LightPoints[i].m + 1).ToString()));
                if (((i + 1) % 5) == 0)
                {
                    sb.Append("\r\n");
                }
                else
                {
                    sb.Append("\t");
                }
                if (i > 98)
                {
                    report.InsertValue("亮点前100个", "(亮点前100个)");
                    break;
                }
            }
            report.InsertValue("亮点位置", sb.ToString());

            report.InsertValue("暗点个数", Calc2.DarkPoints.Count.ToString());
            sb = new StringBuilder();
            for (int i = 0; i < Calc2.DarkPoints.Count; i++)
            {
                sb.Append(String.Format("[{0,4},{1,4}]", (Calc2.DarkPoints[i].n + 1).ToString(), (Calc2.DarkPoints[i].m + 1).ToString()));
                if (((i + 1) % 5) == 0)
                {
                    sb.Append("\r\n");
                }
                else
                {
                    sb.Append("\t");
                }
                if (i > 98)
                {
                    report.InsertValue("暗点前100个", "(暗点前100个)");
                    break;
                }
            }
            report.InsertValue("暗点位置", sb.ToString());
            report.SaveDocument(filename); 
        }
    }
}
